<template>
  <div class="cartcontrol" @click.stop>
    <transition name="move">
      <div 
        class="cart-decrease"
        v-show="food.count>0" 
        @click="decreaseCart">
        <span class="icon icon-remove_circle_outline"></span>
      </div>
    </transition>
    <div class="cart-count" v-show="food.count">{{this.food.count}}</div>
    <div class="cart-add icon-add_circle" @click="addCart"></div>
  </div>
</template>

<script>
import Vue from 'vue'

export default {
  name: 'Cartcontrol',
  props: {
    food: {
      type: Object,
      default() {
        return {
          count: 10,
          price: 20
        }
      }
    }
  },
  methods: {
    addCart(e) {
      if(!this.food.count) {
        Vue.set(this.food, "count", 1)
        // this.food.count = 1
      } else {
        this.food.count ++
      }
      this.$emit("cartAdd", e.target)
    },
    decreaseCart() {
      if(this.food.count > 0) {
        this.food.count --
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~@/assets/stylus/mixin'
  .cartcontrol
    font-size 0
    .cart-add
      display inline-block
      padding 6px 
      line-height 24px
      font-size 24px
      color rgb(0,160,220)
    .cart-decrease
      display inline-block
      padding 6px
      &.move-enter-active
      &.move-leave-active
        transition all .4s cubic-bezier(1.0, 0.5, 0.8, 1.0)
       .icon
          transition all .4s cubic-bezier(1.0, 0.5, 0.8, 1.0)
      &.move-enter
      &.move-leave-to
        opacity 0
        transform translate3d(24px,0,0)
        .icon
          transform rotate(180deg)
      .icon
        display block
        line-height 24px
        font-size 24px
        color rgb(0,160,220)
    .cart-count
      display inline-block
      vertical-align top
      width 12px
      padding-top 6px
      line-height 24px
      text-align center
      font-size 10px
      color rgb(147,153,159)
</style>
